﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OracleClient;
using System.Text;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{

    public class GB14AB55Data : BaseFunction
    {

        public GB14AB55Data()
            : base()
        {

        }
        public GB14AB55Data(Dictionary<string, object> DicGlobalPara)
            : base(DicGlobalPara)
        {
        }
        public DataSet GetRawData(DataRow dwABPOS)
        {
            DataSet set4Return = new DataSet();
            DataSet setLocal = new DataSet();
            DataSet setResult = new DataSet();
            DataSet setTemp = new DataSet();
            DataTable tableLocal = null;
            string FROMDATE,ENDDATE;            
            FROMDATE = dwABPOS["FROMDATE"].ToString().Trim();
            ENDDATE = dwABPOS["ENDDATE"].ToString().Trim();
            try
            {
                OracleCommand or1 = OracleDB.CreateCommand();

                #region
                or1.CommandText = " select A.GPEINDAT,A.GSART,A.GSHANDLNR,A.GSGARNBEZ, "
                    + " A.GSCFARBE,A.GSCBEZ,A.GABBUCHDAT,SUM(A.WEIGHT) AS WEI,A.ORDERNO,A.ARTICLE, "
                    + " A.D,A.BUCHDAT "
                    + "  from yarn_stock_consumption a where (a.BUCHDAT >= '" + FROMDATE + "' or  '" + FROMDATE + "' is null) "
                    + "  AND (a.BUCHDAT <= '" + ENDDATE + "'  or  '" + ENDDATE + "' is null) "
                    + "  GROUP BY A.GPEINDAT,A.GSART,A.GSHANDLNR,A.GSGARNBEZ, "
                    + " A.GSCFARBE,A.GSCBEZ,A.GABBUCHDAT,A.ORDERNO,A.ARTICLE, "
                    + " A.D,A.BUCHDAT "
                    ;

                #endregion
                setLocal = Connect2Proxy(or1);
                if (setLocal.Tables.Count > 0)
                {
                    tableLocal = setLocal.Tables[0];
                    tableLocal.TableName = "GB14AB55";
                    foreach (DataTable dtTemp in setLocal.Tables)
                    {


                        byte[] b;
                        string value;
                        string ColumnName;
                        foreach (DataRow dwTemp in setLocal.Tables["GB14AB55"].Rows)
                        {
                            ColumnName = "GSHANDLNR";
                            b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString());
                            value = Encoding.GetEncoding("gb2312").GetString(b);
                            dwTemp[ColumnName] = value;

                            ColumnName = "GSGARNBEZ";
                            b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString());
                            value = Encoding.GetEncoding("gb2312").GetString(b);
                            dwTemp[ColumnName] = value;

                            ColumnName = "GSCBEZ";
                            b = Encoding.GetEncoding("ISO-8859-1").GetBytes(dwTemp[ColumnName].ToString());
                            value = Encoding.GetEncoding("gb2312").GetString(b);
                            dwTemp[ColumnName] = value;
                            
                        }
                    }


                    set4Return.Merge(setLocal);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return set4Return;
        }
        public DataSet BuildGBBEW(DataRow dwUI)
        {
            string progress = "查询完成";
            DataSet setReturn = new DataSet();
            DataSet setResult = new DataSet();
            try
            {
                EventDispatcher.Instance.RaiseStatus("查询开始", StatusEventType.StartProgress);
                setResult = GetRawData(dwUI);
                setReturn.Merge(setResult);
                EventDispatcher.Instance.RaiseStatus("查询完成", StatusEventType.StopProgress);
            }
            catch (Exception ex)
            {
                Tracer.Error(ABPOS + ex.StackTrace, ex);
            }
            return setReturn;
        }
    }
}